#!/bin/bash

#https://www.cnblogs.com/116970u/p/11211963.html

# 进入源代码文件夹
cd /opt/auto_publish

chmod a+x -R  cloudvideo
cd cloudvideo

#git接取最新的代码
git reset --hard
git checkout
git pull origin master

#获取当前版本的标识
#GIT_SHORT_CODE = git rev-parse --short HEAD

cd video
#编译java项目
mvn clean  install -Dmaven.test.skip=true

#重命名并复制到发布目录
cd target
rm -rf /opt/auto_publish/publish/cloudvideo.jar
cp -a wuyun-app/target/cloudvideo.jar /opt/auto_publish/publish/

#杀死占用某个端口的进程
#查杀
PID=$(ps -ef | grep cloudvideo.jar | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
    echo Application is already stopped
else
    echo kill $PID
    kill $PID
fi

#启动
nohup java -jar /opt/auto_publish/publish/cloudvideo.jar > /opt/auto_publish/publish/log/web.log &

echo startup finished



